<!--
 * @Description: 接触网临时计划新增或编辑
 * @Author: Liu Zhiwang
 * @Date: 2021-04-13 17:05:40
 * @LastEditTime: 2021-07-29 18:33:54
 * @LastEditors: Liu Zhiwang
-->
<template>
  <div>
    <base-dialog
      class="dialog_box dialog-body-fieldset jcw-repair-edit"
      width="60%"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :loading="dialog.loading"
      :disabled="dialog.disabled"
      @updateData="updateData"
      @open="beforeOpenDialog">
      <el-form
        ref="dataForm"
        :model="dialog.form"
        :rules="rules"
        :disabled="dialog.disabled"
        label-width="120px">
        <fieldset>
          <legend>天窗计划</legend>
          <el-row>
            <el-col :span="8">
              <el-form-item label="计划日期" prop="planDate">
                <el-date-picker
                  v-model="dialog.form.planDate"
                  format="yyyy-MM-dd"
                  type="date"
                  style="width: 100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="作业工区" prop="workareaId">
                <select-tree
                  v-model="dialog.form.workareaId"
                  node-click
                  :options="dataList.deptData"
                  :props="{ label: 'label', value: 'id', parent: 'parentId', children: 'children' }"
                  @nodeClick="changeLine"
                  @clear="dialog.form.workareaId=''" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="线路" prop="lineId">
                <el-select
                  v-model="dialog.form.lineId"
                  :no-data-text="dialog.form.workareaId ? '' : '请先选择工区'"
                  value-key="lineId"
                  placeholder="线路"
                  clearable
                  :popper-append-to-body="false"
                  class="filter-item">
                  <el-option v-for="(value,i) in dataList.lineData" :key="'dutyDeptAttr'+i" :label="value.lineName" :value="value.lineId" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="行别" prop="directionAttr">
                <el-select v-model="dialog.form.directionAttr" value-key="directionId" placeholder="行别" clearable multiple @change="changeDirection">
                  <el-option v-for="(value,i) in dataList.directionData" :key="'direction'+i" :label="value.directionName" :value="value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="margin-top: -1px">
              <div class="time-box">
                <el-form-item label="申请时间" prop="blockMinuteRange">
                  <el-date-picker
                    v-model="dialog.form.blockMinuteRange"
                    format="HH:mm"
                    value-format="yyyy-MM-dd HH:mm"
                    placeholder="申请时间"
                    type="datetimerange"
                    popper-class="daily-car-time-class"
                    @change="getMinutes(dialog.form.blockMinuteRange, 'blockMinute')" />
                </el-form-item>
                <div class="minutes-item"> {{ dialog.form.blockMinute }} 分钟</div>
              </div>
            </el-col>
            <el-col :span="8">
              <el-form-item label="施工等级" prop="dictWorkGradeId">
                <el-select v-model="dialog.form.dictWorkGradeId" value-key="dictWorkGradeId" clearable>
                  <el-option v-for="(list,i) in dataList.workGradeTypeData" :key="'dictWorkGradeId'+i" :label="list.itemName" :value="list.dictionaryId" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="盯控干部" prop="leaderName">
                <select-table
                  v-if="dialog.visible"
                  ref="leaderName"
                  v-model="dialog.form.leaderName"
                  :filter-form="selectTableModelLeaderName.filterForm"
                  :filter-data="selectTableModelLeaderName.filterData"
                  :default-data="dataList.leaderData"
                  :columns="selectTableModelLeaderName.columns"
                  :total="selectTableModelLeaderName.total"
                  :filter-fn="selectTableModelLeaderName.filterFn"
                  @current-change="changeTableItemLeaderName"
                  @clear="dialog.form.leaderName='';dialog.form.leaderId=''" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="盯控干部电话" prop="leaderPhone">
                <el-input v-model="dialog.form.leaderPhone" type="text" maxlength="20" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="登记站" prop="registerSite">
                <el-input v-model="dialog.form.registerSite" type="text" maxlength="20" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="联络员" prop="liaisonMan">
                <select-table
                  v-if="dialog.visible"
                  ref="liaisonMan"
                  v-model="dialog.form.liaisonMan"
                  :filter-form="selectTableModelLiaisonMan.filterForm"
                  :filter-data="selectTableModelLiaisonMan.filterData"
                  :default-data="dataList.liaisonManData"
                  :columns="selectTableModelLiaisonMan.columns"
                  :total="selectTableModelLiaisonMan.total"
                  :filter-fn="selectTableModelLiaisonMan.filterFn"
                  @current-change="changeTableItemFiaisonMan"
                  @clear="dialog.form.liaisonMan='';dialog.form.liaisonManId=''" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联络员电话" prop="liaisonManPhone">
                <el-input v-model="dialog.form.liaisonManPhone" type="text" maxlength="20" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="主体单位" prop="mainUnitId">
                <el-select v-model="dialog.form.mainUnitId" value-key="deptId" clearable>
                  <el-option v-for="(list,i) in dataList.mainUnitData" :key="'mainUnitId'+i" :label="list.deptName" :value="list.deptId" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="施工负责人" prop="workPrincipalPerson">
                <select-table
                  v-if="dialog.visible"
                  ref="workPrincipalPerson"
                  v-model="dialog.form.workPrincipalPerson	"
                  :filter-form="selectTableModelWorkPrincipalPerson.filterForm"
                  :filter-data="selectTableModelWorkPrincipalPerson.filterData"
                  :default-data="dataList.workPrincipalPersonData"
                  :columns="selectTableModelWorkPrincipalPerson.columns"
                  :total="selectTableModelWorkPrincipalPerson.total"
                  :filter-fn="selectTableModelWorkPrincipalPerson.filterFn"
                  @current-change="changeTableItemWorkPrincipalPerson"
                  @clear="dialog.form.workPrincipalPerson	='';dialog.form.workPrincipalPersonId=''" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="施工负责人电话" prop="workPrincipalPersonPhone">
                <el-input v-model="dialog.form.workPrincipalPersonPhone" type="text" maxlength="20" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="施工项目" prop="workProject" label-width="120px">
                <el-input v-model="dialog.form.workProject" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="限速条件(里程、长度、要求)" prop="limitCondition" label-width="120px">
                <el-input v-model="dialog.form.limitCondition" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="行车方式（变化）" prop="trafficWay" label-width="120px">
                <el-input v-model="dialog.form.trafficWay" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="设备变化" prop="equipmentVariation" label-width="120px">
                <el-input v-model="dialog.form.equipmentVariation" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="动车组运行条件" prop="runCondition" label-width="120px">
                <el-input v-model="dialog.form.runCondition" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="其它事项" prop="otherMatter" label-width="120px">
                <el-input v-model="dialog.form.otherMatter" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="作业车运行占用股道" prop="jobRunTrackOccupied" label-width="120px">
                <el-input v-model="dialog.form.jobRunTrackOccupied" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="滚动施工需取消的前次限速（命令号码）" prop="cancelCommandNum" label-width="120px">
                <el-input v-model="dialog.form.cancelCommandNum" maxlength="500" type="textarea" :rows="4" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="施工里程" prop="workMileage" label-width="120px">
                <el-input v-model="dialog.form.workMileage" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="作业区段" prop="workRange" label-width="120px">
                <el-input v-model="dialog.form.workRange" maxlength="1000" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="停电范围" prop="stopPowerRange" label-width="120px">
                <el-input v-model="dialog.form.stopPowerRange" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset>
          <legend>作业完成情况</legend>
          <el-row>
            <el-col :span="8">
              <div class="time-box">
                <el-form-item label="行调给点时间" prop="xdDateTimeRange">
                  <el-date-picker
                    v-model="dialog.form.xdDateTimeRange"
                    format="HH:mm"
                    value-format="yyyy-MM-dd HH:mm"
                    placeholder="行调给点时间"
                    type="datetimerange"
                    popper-class="daily-car-time-class"
                    @change="getMinutes(dialog.form.xdDateTimeRange, 'xdSpendMinutes')" />
                </el-form-item>
                <div class="minutes-item"> {{ dialog.form.xdSpendMinutes }} 分钟</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="time-box">
                <el-form-item label="电调给点时间" prop="ddDateTimeRange">
                  <el-date-picker
                    v-model="dialog.form.ddDateTimeRange"
                    format="HH:mm"
                    value-format="yyyy-MM-dd HH:mm"
                    placeholder="电调给点时间"
                    type="datetimerange"
                    popper-class="daily-car-time-class"
                    @change="getMinutes(dialog.form.ddDateTimeRange, 'ddSpendMinutes')" />
                </el-form-item>
                <div class="minutes-item"> {{ dialog.form.ddSpendMinutes }} 分钟</div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="time-box">
                <el-form-item label="检修时间" prop="repairDateTimeRange">
                  <el-date-picker
                    v-model="dialog.form.repairDateTimeRange"
                    format="HH:mm"
                    value-format="yyyy-MM-dd HH:mm"
                    placeholder="检修时间"
                    type="datetimerange"
                    popper-class="daily-car-time-class"
                    @change="getMinutes(dialog.form.repairDateTimeRange, 'repairSpendMinutes')" />
                </el-form-item>
                <div class="minutes-item"> {{ dialog.form.repairSpendMinutes }} 分钟</div>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="检修列" prop="repairCol">
                <el-input v-model="dialog.form.repairCol" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="梯车数" prop="ladderCarCount">
                <el-input v-model="dialog.form.ladderCarCount" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="轨道车数" prop="railCarCount">
                <el-input v-model="dialog.form.railCarCount" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="人工组数" prop="repairPeopleGroupCount">
                <el-input v-model="dialog.form.repairPeopleGroupCount" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="作业人数" prop="repairPeopleCount">
                <el-input v-model="dialog.form.repairPeopleCount" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="作业量(条公里)" class="padding-right-4" prop="repairAmount">
                <el-input v-model="dialog.form.repairAmount" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="作业完成内容" prop="repairCompleteContent">
                <el-input v-model="dialog.form.repairCompleteContent" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="memo">
                <el-input v-model="dialog.form.memo" maxlength="500" type="textarea" resize="none" />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset>
          <legend>附件</legend>
          <el-form-item label="附件上传">
            <UploadFile :model="fileModal" @on-success="uploadSuccess" />
          </el-form-item>
        </fieldset>
      </el-form>
    </base-dialog>
  </div>
</template>
<script>
import { valiInt, valiDecimalPoint, valiIntPhone } from '@/utils/validate'
import dayjs from 'dayjs'
import { initSkyLightPlan, getPlanCode, addEditJcwTempRepairData } from '@/api/jcwsc/production-daily/catenary-safety-production'
import { getDirectionList, getStaffList, getListFindByDtId, getLineList, getDeptAndSubDeptList, findManageUnitDeptList, findManageDeptTree } from '@/api/main'
import UploadFile from '@/views/cms/jcwsc/components/UploadFile'

export default {
  components: {
    UploadFile
  },
  props: {
    dialog: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      fileModal: {
        title: '',
        visible: false,
        pathList: [],
        fileList: [],
        type: 1,
        bizType: '1',
        key: 0,
        index: 0,
        isDetail: false,
        uploadType: 'file'
      },
      selectTableModelLeaderName: { // 盯控干部
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
          // 暂时注释
          // dtId: 'POSITION_TYPE',
          // dtItemValue: '0002'
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          },
          deptId: {
            clearable: false,
            key: 'deptId',
            type: 'selectTree',
            title: '部门',
            placeholder: '请选择部门',
            options: [],
            props: {
              label: 'label',
              value: 'id',
              parent: 'parentId',
              children: 'children'
            },
            changeFn: _ => {
              this.$refs.leaderName.$refs.customSelect.focus()
            }
          }
        },
        columns: [
          { property: 'staffName', label: '盯控干部' },
          { property: 'deptName', label: '所属部门' },
          { property: 'phone', label: '联系方式' }
        ],
        total: 0,
        filterFn: getStaffList
      },
      selectTableModelLiaisonMan: { // 联络员
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
          // 暂时注释
          // dtId: 'POSITION_TYPE',
          // dtItemValue: '0001'
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          },
          deptId: {
            clearable: false,
            key: 'deptId',
            type: 'selectTree',
            title: '部门',
            placeholder: '请选择部门',
            options: [],
            props: {
              label: 'label',
              value: 'id',
              parent: 'parentId',
              children: 'children'
            },
            changeFn: _ => {
              this.$refs.liaisonMan.$refs.customSelect.focus()
            }
          }
        },
        columns: [
          { property: 'staffName', label: '联络员' },
          { property: 'deptName', label: '所属部门' },
          { property: 'phone', label: '联系方式' }
        ],
        total: 0,
        filterFn: getStaffList
      },
      selectTableModelWorkPrincipalPerson: { // 施工负责人
        filterForm: {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
          // 暂时注释
          // dtId: 'POSITION_TYPE',
          // dtItemValue: '0001'
        },
        filterData: {
          staffName: {
            key: 'staffName',
            type: 'input',
            placeholder: '姓名'
          },
          deptId: {
            clearable: false,
            key: 'deptId',
            type: 'selectTree',
            title: '部门',
            placeholder: '请选择部门',
            options: [],
            props: {
              label: 'label',
              value: 'id',
              parent: 'parentId',
              children: 'children'
            },
            changeFn: _ => {
              this.$refs.workPrincipalPerson.$refs.customSelect.focus()
            }
          }
        },
        columns: [
          { property: 'staffName', label: '施工负责人' },
          { property: 'deptName', label: '所属部门' },
          { property: 'phone', label: '联系方式' }
        ],
        total: 0,
        filterFn: getStaffList
      },
      timeout: null,
      rules: {
        planDate: [
          { required: true, message: '请填选计划日期', trigger: 'change' }
        ],
        planCode: [
          { required: true, message: '请选填计划号', trigger: 'change' },
          { required: true, message: '请选填计划号', trigger: 'blur' }
        ],
        workareaId: [
          { required: true, message: '请选择工区', trigger: 'change' }
        ],
        lineId: [
          { required: true, message: '请选择线路名称', trigger: 'change' }
        ],
        directionAttr: [
          { required: true, message: '请选择行别', trigger: 'change' }
        ],
        skylightType: [
          { required: true, message: '请选择行别', trigger: 'change' }
        ],
        // leaderName: [
        //   { required: true, message: '请选择盯控干部', trigger: 'change' }
        // ],
        workRange: [
          { required: true, message: '请填写作业区段', trigger: 'blur' }
        ],
        stopPowerRange: [
          { required: true, message: '请填写停电范围', trigger: 'blur' }
        ],
        planType: [
          { required: true, message: '请选择计划类型', trigger: 'change' }
        ],
        mainUnitId: [
          { required: true, message: '请选择主体单位', trigger: 'change' }
        ],
        liaisonMan: [
          { required: true, message: '请选择联络员', trigger: 'change' }
        ],
        workPrincipalPerson: [
          { required: true, message: '请选择施工负责人', trigger: 'change' }
        ],
        tempPlan: [
          { required: true, message: '请选择临时计划', trigger: 'change' }
        ],
        repairPlanStatus: [
          { required: true, message: '请选择计划状态', trigger: 'change' }
        ],
        blockMinuteRange: [
          { required: true, message: '请填选申请时间', trigger: 'change' }
        ],
        // xdDateTimeRange: [
        //   { required: true, message: '请填选行调给点时间', trigger: 'change' }
        // ],
        // ddDateTimeRange: [
        //   { required: true, message: '请填选电调给点时间', trigger: 'change' }
        // ],
        // repairDateTimeRange: [
        //   { required: true, message: '请填选检修时间', trigger: 'change' }
        // ],
        registerSite: [
          { required: true, message: '请填写登记站', trigger: 'blur' }
        ],
        // repairCol: [
        //   { required: true, message: '请填写检修列', trigger: 'blur' },
        //   { validator: valiInt, trigger: 'blur' }
        // ],
        // ladderCarCount: [
        //   { required: true, message: '请填写梯车数', trigger: 'blur' },
        //   { validator: valiInt, trigger: 'blur' }
        // ],
        // railCarCount: [
        //   { required: true, message: '请填写轨道车数', trigger: 'blur' },
        //   { validator: valiInt, trigger: 'blur' }
        // ],
        // repairPeopleGroupCount: [
        //   { required: true, message: '请填写人工组数', trigger: 'blur' },
        //   { validator: valiInt, trigger: 'blur' }
        // ],
        // repairPeopleCount: [
        //   { required: true, message: '请填写作业人数', trigger: 'blur' },
        //   { validator: valiInt, trigger: 'blur' }
        // ],
        repairAmount: [
          // { required: true, message: '请填写作业量(条公里)', trigger: 'blur' },
          { validator: valiDecimalPoint, trigger: 'blur' }
        ],
        groundWireGoup: [
          { required: true, message: '请填写地线组', trigger: 'blur' },
          { validator: valiInt, trigger: 'blur' }
        ],
        workProject: [
          { required: true, message: '请填写施工项目', trigger: 'blur' }
        ],
        workMileage: [
          { required: true, message: '请填写施工里程', trigger: 'blur' }
        ],
        // repairCompleteContent: [
        //   { required: true, message: '请填写作业完成内容', trigger: 'blur' }
        // ],
        followCadre: [
          { validator: valiIntPhone, trigger: 'blur' }
        ]
      },
      dataList: {
        deptData: [], // 部门树
        lineData: [], // 线路
        directionData: [], // 行别
        skylightTypeData: [
          { label: '垂直天窗', value: 'VERTICAL' },
          { label: 'V型天窗', value: 'V_TYPE' }
        ], // 天窗类型
        leaderData: [], // 盯控干部
        liaisonManData: [], // 联络员
        workPrincipalPersonData: [], // 施工负责人
        planTypeData: [
          { label: '配合施工', value: 'COOPERATE_CONSTRUCT' },
          { label: '施工', value: 'CONSTRUCT' },
          { label: '维修', value: 'REPAIR' }
        ], // 计划类型
        repairPlanStatusData: [
          { label: '取消', value: 'Cancel' },
          { label: '完成', value: 'Complete' },
          { label: '未开始', value: 'NotStart' }
        ], // 计划状态
        workGradeTypeData: [], // 施工等级
        getPlanList: [], // 计划号
        mainUnitData: [] // 主体单位
      }
    }
  },
  watch: {
    'dialog.visible'() {
      if (this.dialog.visible) {
        if (this.dialog.type !== 'add') {
          this.dialog.form = this.handleDataForm(this.dialog.form)
        }
        // 附件
        var tempArr = []
        this.dialog.form.filesList.forEach(item => {
          tempArr.push(item.filePath)
        })
        this.showFile(tempArr, 1, 0, 0, false, this.dialog.form.filesList)

        // 重置页码、查询
        this.getList()
        this.getStaffList()
      }
    }
  },
  methods: {
    // 选择行别
    changeDirection(e) {
      var tempData = this.dialog.form
      tempData.directionAttr = e
      this.dialog.form = JSON.parse(JSON.stringify(tempData))
    },
    // 计划号查询
    querySearchAsync(queryString, cb) {
      var getPlanList = this.dataList.getPlanList
      var results = queryString ? getPlanList.filter(this.createStateFilter(queryString)) : getPlanList
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        cb(results)
      }, 1000 * Math.random())
    },

    createStateFilter(queryString) {
      return (state) => {
        return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
      }
    },

    // 显示附件
    showFile(pathList, type, key, index, isDetail, fileList) {
      this.fileModal = {
        title: '',
        visible: true,
        pathList: pathList,
        fileList: fileList,
        type,
        bizType: '1',
        key,
        index,
        isDetail: isDetail,
        uploadType: 'file'
      }
    },
    uploadSuccess(filelist, type, key, index, fileArr) { // 上传成功
      this.dialog.form.filesList = fileArr
      this.notifiySuccess('上传成功')
    },
    // 获取下拉数据、字典
    getList() {
      // 获取计划号
      getPlanCode().then(response => {
        var temp = []
        for (var item of response.data) {
          temp.push({ value: item })
        }
        this.dataList.getPlanList = temp
      })

      // 获取行别数据
      getDirectionList({ railType: '' }).then(response => {
        this.dataList.directionData = response.data
      })

      // 取消原因
      getListFindByDtId({ dtId: 'WORK_GRADE_TYPE' }).then(response => {
        this.dataList.workGradeTypeData = response.data
      })

      // 获取线路
      getLineList({ railType: '' }).then(response => {
        this.dataList.lineData = response.data
      })

      // 获取本部门及下属树
      getDeptAndSubDeptList({ deptCode: this.dialog.deptCode }).then(response => {
        this.dataList.deptData = response.data
      })

      // 获取角色管理部门树
      findManageDeptTree().then(response => {
        this.selectTableModelLeaderName.filterData.deptId.options = response.data
        this.selectTableModelLiaisonMan.filterData.deptId.options = response.data
        this.selectTableModelWorkPrincipalPerson.filterData.deptId.options = response.data
      })

      // 获取部门树
      findManageUnitDeptList().then(response => {
        this.dataList.mainUnitData = response.data
      })
    },

    // 选择盯控干部
    changeTableItemLeaderName(row) {
      var tempData = this.dialog.form
      tempData.leaderName = row.staffName
      tempData.leaderPhone = row.phone
      tempData.leaderId = row.deptId
      this.dialog.form = JSON.parse(JSON.stringify(tempData))
    },

    // 选择联络员
    changeTableItemFiaisonMan(row) {
      var tempData = this.dialog.form
      tempData.liaisonMan = row.staffName
      tempData.liaisonManPhone = row.phone
      tempData.liaisonManId = row.deptId
      this.dialog.form = JSON.parse(JSON.stringify(tempData))
    },

    // 选择施工负责人
    changeTableItemWorkPrincipalPerson(row) {
      var tempData = this.dialog.form
      tempData.workPrincipalPerson = row.staffName
      tempData.workPrincipalPersonPhone = row.phone
      tempData.workPrincipalPersonId = row.deptId
      this.dialog.form = JSON.parse(JSON.stringify(tempData))
    },

    // 计算时间差
    getMinutes(dateTimeRange, minuteString) {
      if (dateTimeRange) {
        var startTime = new Date(dateTimeRange[0])
        var endTime = new Date(dateTimeRange[1])
        if (startTime || endTime) {
          var totalMinutes = 0
          totalMinutes = Math.floor((endTime - startTime) / (1000 * 60))
        }
        if (minuteString === 'blockMinute') {
          this.dialog.form.blockMinute = totalMinutes || 0
        } else if (minuteString === 'xdSpendMinutes') {
          this.dialog.form.xdSpendMinutes = totalMinutes || 0
        } else if (minuteString === 'ddSpendMinutes') {
          this.dialog.form.ddSpendMinutes = totalMinutes || 0
        } else if (minuteString === 'repairSpendMinutes') {
          this.dialog.form.repairSpendMinutes = totalMinutes || 0
        }
      } else {
        if (minuteString === 'blockMinute') {
          this.dialog.form.blockMinute = 0
        } else if (minuteString === 'xdSpendMinutes') {
          this.dialog.form.xdSpendMinutes = 0
        } else if (minuteString === 'ddSpendMinutes') {
          this.dialog.form.ddSpendMinutes = 0
        } else if (minuteString === 'repairSpendMinutes') {
          this.dialog.form.repairSpendMinutes = 0
        }
      }
    },

    // 获取人员信息接口
    getStaffList() {
      this.$nextTick(_ => {
        // 盯控干部
        this.dataList.leaderData = []
        this.selectTableModelLeaderName.total = 0
        this.selectTableModelLeaderName.filterForm = Object.assign({}, this.selectTableModelLeaderName.filterForm, {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
        })
        // 联络员
        this.dataList.liaisonManData = []
        this.selectTableModelLiaisonMan.total = 0
        this.selectTableModelLiaisonMan.filterForm = Object.assign({}, this.selectTableModelLiaisonMan.filterForm, {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
        })
        // 施工负责人
        this.dataList.workPrincipalPersonData = []
        this.selectTableModelWorkPrincipalPerson.total = 0
        this.selectTableModelWorkPrincipalPerson.filterForm = Object.assign({}, this.selectTableModelWorkPrincipalPerson.filterForm, {
          page: 1,
          size: 10,
          staffName: '',
          deptId: ''
        })
        const form = this.selectTableModelWorkPrincipalPerson.filterForm
        getStaffList(form)
          .then((response) => {
            // 盯控干部
            this.dataList.leaderData = response.data.records
            this.selectTableModelLeaderName.total = response.data.total
            // 联络员
            this.dataList.liaisonManData = response.data.records
            this.selectTableModelLiaisonMan.total = response.data.total
            // 施工负责人
            this.dataList.workPrincipalPersonData = response.data.records
            this.selectTableModelWorkPrincipalPerson.total = response.data.total
          })
      })
    },

    // 计划号初始化data
    initSkyLightPlan() {
      if (this.dialog.form.planDate && this.dialog.form.planCode) {
        var initSkyLightParams = {
          planDate: this.dialog.form.planDate ? dayjs(this.dialog.form.planDate).format('YYYY-MM-DD') : '',
          planCode: this.dialog.form.planCode || ''
        }
        initSkyLightPlan(initSkyLightParams).then(response => {
          if (response.data) {
            if (response.data.directionMcode && typeof (response.data.directionMcode) === 'string') {
              response.data.directionMcode = response.data.directionMcode ? response.data.directionMcode.split(',') : []
              response.data.directionName = response.data.directionName ? response.data.directionName.split(',') : []
              response.data.directionId = response.data.directionId ? response.data.directionId.split(',') : []
            }
            response.data.directionAttr = []
            if (response.data.directionName.length) {
              for (var i in response.data.directionName) {
                var obj = {
                  directionMcode: response.data.directionMcode[i],
                  directionName: response.data.directionName[i],
                  directionId: response.data.directionId[i]
                }
                response.data.directionAttr.push(obj)
              }
            }

            // 申请时间
            if (response.data.blockStartTime && response.data.blockEndTime) {
              response.data.blockMinuteRange = [response.data.blockStartTime, response.data.blockEndTime]
            } else {
              response.data.blockMinuteRange = []
            }
            delete response.data.id
            this.dialog.form = Object.assign(this.dialog.form, response.data)
          }
        })
      }
    },

    // 处理表单数据
    handleDataForm(data) {
      if (data.directionMcode && typeof (data.directionMcode) === 'string') {
        data.directionMcode = data.directionMcode ? data.directionMcode.split(',') : []
        data.directionName = data.directionName ? data.directionName.split(',') : []
        data.directionId = data.directionId ? data.directionId.split(',') : []
      }
      data.directionAttr = []
      if (data.directionName && data.directionName.length) {
        for (var i in data.directionName) {
          var obj = {
            directionMcode: data.directionMcode[i],
            directionName: data.directionName[i],
            directionId: data.directionId[i]
          }
          data.directionAttr.push(obj)
        }
      }
      // 申请时间
      var blockStartTime = data.blockStartTime ? data.blockStartTime : ''
      var blockEndTime = data.blockEndTime ? data.blockEndTime : ''
      if (blockStartTime && blockStartTime) {
        data.blockMinuteRange = [blockStartTime, blockEndTime]
      }
      // 行调时间
      var xdStartTime = data.xdBeginDate ? data.xdBeginDate : ''
      var xdOverTime = data.xdEndDate ? data.xdEndDate : ''
      if (xdStartTime && xdOverTime) {
        data.xdDateTimeRange = [xdStartTime, xdOverTime]
      }
      // 电调时间
      var ddStartTime = data.ddBeginDate ? data.ddBeginDate : ''
      var ddOverTime = data.ddEndDate ? data.ddEndDate : ''
      if (ddStartTime && ddOverTime) {
        data.ddDateTimeRange = [ddStartTime, ddOverTime]
      }
      // 检修时间
      var repairStartTime = data.repairBeginDate ? data.repairBeginDate : ''
      var repairOverTime = data.repairEndDate ? data.repairEndDate : ''
      if (repairStartTime && repairOverTime) {
        data.repairDateTimeRange = [repairStartTime, repairOverTime]
      }
      return data
    },

    // 回调方法
    updateData() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.dialog.loading = true
          // 行别
          if (this.dialog.form.directionAttr.length) {
            var directionIds = []
            var directionNames = []
            var directionMcodes = []
            for (var i in this.dialog.form.directionAttr) {
              directionIds.push(this.dialog.form.directionAttr[i].directionId)
              directionNames.push(this.dialog.form.directionAttr[i].directionName)
              directionMcodes.push(this.dialog.form.directionAttr[i].directionMcode)
            }
            this.dialog.form.directionId = directionIds.join(',')
            this.dialog.form.directionName = directionNames.join(',')
            this.dialog.form.directionMcode = directionMcodes.join(',')
          }
          // 申请时间
          if (this.dialog.form.blockMinuteRange) {
            this.dialog.form.blockStartTime = this.dialog.form.blockMinuteRange[0]
            this.dialog.form.blockEndTime = this.dialog.form.blockMinuteRange[1]
          } else {
            this.dialog.form.blockStartTime = ''
            this.dialog.form.blockEndTime = ''
          }
          // 行调时间
          if (this.dialog.form.xdDateTimeRange) {
            this.dialog.form.xdBeginDate = this.dialog.form.xdDateTimeRange[0]
            this.dialog.form.xdEndDate = this.dialog.form.xdDateTimeRange[1]
          } else {
            this.dialog.form.xdBeginDate = ''
            this.dialog.form.xdEndDate = ''
          }
          // 电调时间
          if (this.dialog.form.ddDateTimeRange) {
            this.dialog.form.ddBeginDate = this.dialog.form.ddDateTimeRange[0]
            this.dialog.form.ddEndDate = this.dialog.form.ddDateTimeRange[1]
          } else {
            this.dialog.form.ddBeginDate = ''
            this.dialog.form.ddEndDate = ''
          }
          // 检修时间
          if (this.dialog.form.repairDateTimeRange) {
            this.dialog.form.repairBeginDate = this.dialog.form.repairDateTimeRange[0]
            this.dialog.form.repairEndDate = this.dialog.form.repairDateTimeRange[1]
          } else {
            this.dialog.form.repairBeginDate = ''
            this.dialog.form.repairEndDate = ''
          }
          addEditJcwTempRepairData(this.dialog.form)
            .then((response) => {
              this.dialog.loading = false
              this.$emit('updateData', this.dialog.form)
            })
            .catch((_) => {
              this.dialog.loading = false
            })
        }
      })
    },
    beforeOpenDialog() {
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    },
    changeLine() {}
  }
}
</script>
<style lang="scss">
.jcw-repair-edit {
  .time-box {
    display: flex;
    .minutes-item {
      display: inline-block;
      padding-top: 8px;
      height: 0px;
      white-space: nowrap;
    }
  }
}
</style>
